var $ = layui.jquery;
//刷新页面
function init() {
    window.location.reload();
}
//显示列表
function showSV() {
    header.style.display = 'block';
    headerHot();
}
//显示机构
function showJG() {
    var mech = document.getElementById('organ');
    mech.style.display = '';
}
//修改课程为机构
function Hidden() {
    var keyword = document.getElementById('keyword');
	var chazhi = RegExp(/搜索课程/);//查找对象
	// console.log(chazhi.test(keyword.placeholder));
	// if(chazhi.test(keyword.placeholder))
	// if(keyword.placeholder.search('搜索课程') != -1)
	if(keyword.placeholder.indexOf('搜索课程') != -1)
	{
		document.getElementById('Course').innerText = '机构';
		document.getElementById('organ').innerText = '课程';
		var mech = document.getElementById('organ');
		mech.style.display = 'none';
		keyword.placeholder = '搜索机构';
	}else {
		document.getElementById('Course').innerText = '课程';
		document.getElementById('organ').innerText = '机构';
		var mech = document.getElementById('organ');
		mech.style.display = 'none';
		keyword.placeholder = '搜索课程';
	}
}
//判断点击的位置
function clickHidden(eve){
    var mech = document.getElementById('organ');
    // 通过eve.target.className可以获得触发对象的类
    if( eve.target.className!='mod-search' && eve.target.className != 'mod-dropdown')
        mech.style.display='none';
}
//addEventListener是侦听事件并处理相应的函数，click是全局监听
document.addEventListener('click',clickHidden);
//隐藏列表
function hideSV() {
    header.style.display = 'none';
}
//获取列表包裹元素
function headerHot() {
    var eHeader = document.getElementById('header');
    eHeader.innerHTML = `<div class="header-hot">
        <p class="hot-list-tt">热门搜索</p>
        <div class="hot-word-list">
        <a class="hot-word-item" target="_blank" href="javascript:;"> 财会品牌日 </a>
        <a class="hot-word-item" target="_blank" href="javascript:;"> 高等数学 </a>
        <a class="hot-word-item" target="_blank" href="javascript:;"> ug </a>
        <a class="hot-word-item" target="_blank" href="javascript:;"> vscode </a>
        <a class="hot-word-item" target="_blank" href="javascript:;"> python </a>
        </div>
        </div>`;
}
//热搜内容
function testAjax() {
    var eInput = document.getElementById('keyword');
    var eHeader = document.getElementById('header');
    if(eInput.value == ''){
        headerHot();
    }else {
    $.ajax({
        url: 'http://192.168.3.224:8080/demo/find',
        type: 'get',
        datatype: 'json',
        data: 'findBean.e='+eInput.value,
        success: function (result) {
            $.each(result.rs.rs, function (i, n) {
                console.log(i);
                console.log(n);
                eHeader.innerHTML = '<a href="#" class="hot-word-item">'+n.title+'</a>';
            });
console.log(result);
        }
    });
}
}
//显示登录页面
function MyShow() {
    var login = document.getElementById('login');
    login.style.display = 'block';
}
//隐藏登录页面
function MyClose() {
    var login = document.getElementById('login');
    login.style.display = 'none';
}
//输入框判断
function login() {
    // var re =/(^\w+@[a-zA-Z0-9]{2,10}(?:\.[a-z]{2,4}){1,3}$)/;
    var re = /^([a-zA-z_]{1})([\w]*)$/;
    var txt = /^[0-9]$/;
    var user = document.getElementById('user');
    var pwd = document.getElementById('pwd');
    var suc = document.getElementById('suc');
    var Name = document.getElementById('name');
    //判断用户名
    if(!re.test(user.value)){
        suc.style.display = 'block';
        suc.innerText = '请输入正确的用户名';
        setTimeout(function () {
            suc.style.display = 'none';
        },2000);
        return;
    }
    //判断密码
    if(pwd.value == ''){
        suc.style.display = 'block';
        suc.innerText = '请输入密码';
        setTimeout(function () {
            suc.style.display = 'none';
        },2000);
        return;
    }
    $.ajax({
        url: 'http://192.168.3.224:8080/demo/login',
        type: 'post',
        datatype: 'json',
        data: {'userBeen.username':user.value,'userBeen.pwd':pwd.value},
        success: function (result) {
           if (result.le.code == 1){//登录成功
               layer.msg(result.le.msg,{time:800,icon:6});
               setTimeout(function () {//一秒后隐藏登录页面
                   MyClose();
               },1000);
               Name.innerHTML =
                   `<div class="userName" style="width: 100px">
                         <p>
                             <img src=`+result.le.le.url+'>'+result.userBeen.username+`
                         </p>
                         <ul class="name-list">
                                <li><a href="https://ke.qq.com/admin/personal_join.html">课程表</a></li>
                                <li><a href="https://ke.qq.com/admin/agency_join.html">全部订单</a></li>
                                <li><a href="https://ke.qq.com/sale.html">个人信息</a></li>
                                <li><a href="#" onclick="Goout()">退出</a></li>
                            </ul>
                    </div>`;
           }else {//登录失败
               layer.msg(result.le.msg,{time:800,icon:0});
           }
            console.log(11111111);
            console.log(result);
        }
    });
}
function Goout() {
    init();
}